from datetime import datetime

from flask import Flask,render_template

app = Flask(__name__)

@app.template_filter('hand_time')
def hand_time(value):
    #获取当前时间
    now = datetime.now()
    #将相差的时间转换为秒
    temp_stamp = (now - value).total_seconds()
    if temp_stamp < 60:
        return '1分钟之前'
    elif 60 <= temp_stamp < 60*60:
        return '1小时之前'
    elif 60*60 <= temp_stamp < 60*60*24:
        hours = int(temp_stamp/(60*60))
        return f'{hours}小时之前'
    elif 60*60*24 <= temp_stamp <= 60*60*24*30:
        days = int(temp_stamp/(60*60*24))
        return f'{days}天之前'
    else:
        return value

#路由地址
@app.route('/')
def index():
    time = datetime(2025, 10, 10, 12, 0, 0)
    return render_template('index09.html',time = time)

if __name__ == '__main__':
    #启动web应用服务
    app.run(debug=True)